﻿@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inherits DbContextPage

<RadzenCard class="m-4" style="display: flex; align-items: center; gap: 0.5rem">
    <RadzenCheckBox @bind-Value=@allowCompositeDataCells Name="CheckBox1" TValue="bool" Change=@(args => grid.Reload())/>
    <RadzenLabel Text="Allow composite data cells" Component="CheckBox1" />
</RadzenCard>
<RadzenDataGrid @ref="grid" AllowGrouping=true AllowCompositeDataCells="@allowCompositeDataCells" AllowSorting="true" AllowFiltering="true" FilterPopupRenderMode="PopupRenderMode.OnDemand"  FilterMode="FilterMode.Advanced" PageSize="5" AllowPaging="true"  
    Data="@employees" TItem="Employee" ColumnWidth="300px" LogicalFilterOperator="LogicalFilterOperator.Or" Style="height:420px" class="m-4" HideGroupedColumn="false" >
    <Columns>
        <RadzenDataGridColumn TItem="Employee" Property="EmployeeID" Filterable="false" Title="ID" Frozen="true" Width="80px" TextAlign="TextAlign.Center" />
        <RadzenDataGridColumn TItem="Employee" Title="Photo" Frozen="true" Sortable="false" Filterable="false" Width="80px" TextAlign="TextAlign.Center" >
            <Template Context="data">
                <RadzenImage Path="@data.Photo" class="rz-gravatar" />
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="Employee" Title="Title" Property="TitleOfCourtesy" Filterable=@allowCompositeDataCells Sortable=@allowCompositeDataCells>
            <Columns>
                <RadzenDataGridColumn TItem="Employee" Property="FirstName" Title="FirstName" Width="140px" Filterable=@allowCompositeDataCells Sortable=@allowCompositeDataCells>
                        <Columns>
                        <RadzenDataGridColumn TItem="Employee" Property="Title" Title="Job Title" Width="200px" />
                        <RadzenDataGridColumn TItem="Employee" Property="BirthDate" Title="Birth Date" FormatString="{0:d}" Width="140px" />
                        <RadzenDataGridColumn TItem="Employee" Property="HireDate" Title="Hire Date" FormatString="{0:d}" Width="140px" />
                        </Columns>
                </RadzenDataGridColumn>
                <RadzenDataGridColumn TItem="Employee" Property="LastName" Title="LastName" Width="140px" Filterable=@allowCompositeDataCells Sortable=@allowCompositeDataCells>
                    <Columns>
                        <RadzenDataGridColumn TItem="Employee" Property="Address" Title="Address" Width="200px" />
                    </Columns>
                </RadzenDataGridColumn>
                <RadzenDataGridColumn TItem="Employee" Property="City" Title="City" Width="140px" />
            </Columns>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="Employee" Property="Region" Title="Region" Width="140px" />
        <RadzenDataGridColumn TItem="Employee" Property="PostalCode" Title="Postal Code" Width="140px" />
        <RadzenDataGridColumn TItem="Employee" Property="Country" Title="Country" Width="140px" />
        <RadzenDataGridColumn TItem="Employee" Property="HomePhone" Title="Home Phone" Width="140px" />
        <RadzenDataGridColumn TItem="Employee" Property="Extension" Title="Extension" Width="140px" />
        <RadzenDataGridColumn TItem="Employee" Property="Notes" Title="Notes" Width="300px" />
    </Columns>
</RadzenDataGrid>

@code {
    bool allowCompositeDataCells = false;
    RadzenDataGrid<Employee> grid;
    IEnumerable<Employee> employees;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        employees = dbContext.Employees;
    }
}